Skip to content

Parse configuration into typed options structs with cobra - #379

Draft
fwiesel wants to merge 3 commits into
mainfrom
config/cobra
Draft

fwiesel wants to merge 3 commits into
mainfrom
config/cobra

Conversation

@fwiesel

@fwiesel fwiesel commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Keep operator parameters in module-owned typed options structs.
Adding a parameter changes its module and the chart environment values,
not a central parameter registry.

Cobra and pflag parse the flags.
Viper supplies environment values.
Explicit flags take precedence. --help documents the environment names.
Invalid configuration fails at startup.

Trait concurrency uses map[string]int and native StringToIntVar parsing.
Malformed integers fail during parsing. Validation rejects limits below 1
and empty or whitespace-padded trait names. The lowest matching limit wins,
with the default as the cap and a minimum result of 1.

The chart removes six --flag=$(ENV_VAR) arguments in a separate commit.

Alternative to #373, which uses go-flagsfiller instead of cobra and viper.
Existing tests retain the option wiring changes. No new repository tests.

Relates to #13.

Layout reduction round (2026-11-01)

Controller-owned options now live in their controller files:

  • eviction options → internal/controller/eviction/controller.go
  • certificate options → internal/controller/node_certificate_controller.go
  • shared settings → internal/controller/hypervisor_controller.go (used by the manager and the Hypervisor controller only)

The separate internal/controller/eviction/options.go, internal/controller/options.go, and internal/config/options.go files no longer exist.

Churn vs PR base (added + deleted lines): 505 → 436.

Future settings: add the field (tag + default) to the owning options struct in its controller file — no central registration. Separate new semantic field groups with a blank line to keep reformatting churn low.

@fwiesel
fwiesel force-pushed the config/cobra branch 3 times, most recently from 47e0676 to 5f023ef Compare October 31, 2026 09:52
A controller parameter should not need a central configuration registry.
Let each module declare typed options and flags. Use cobra and viper for
command-line parsing and environment values. Flags take precedence.
Keep the chart environment values and document them in --help.

Use native integer trait limits so malformed values fail during parsing.
Keep concurrency guards and the existing certificate namespace wiring.

Signed-off-by: Fabian Wiesel <fabian.wiesel@sap.com>
The manager reads its settings from the environment, so drop the
--flag=$(ENV_VAR) container arguments.

Signed-off-by: Fabian Wiesel <fabian.wiesel@sap.com>
settings now live next to their owning controllers, so adding a setting touches one file per controller plus the chart.
Signed-off-by: Fabian Wiesel <fabian.wiesel@sap.com>
@github-actions

Copy link
Copy Markdown

Merging this branch will decrease overall coverage

Impacted Packages Coverage Δ 🤖
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller 73.67% (-1.76%) 👎
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/eviction 64.45% (-3.42%) 👎
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/global 0.00% (-100.00%) 💀 💀 💀 💀 💀
Coverage details

Compared to commit cfee313 (run #43438290245)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/cobaltcore-dev/openstack-hypervisor-operator/cmd/main.go 0.00% (ø) 0 0 0
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/eviction/controller.go 64.45% (-3.42%) 211 (+18) 136 (+5) 75 (+13) 👎
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/hypervisor_controller.go 72.18% (-7.82%) 133 (+13) 96 37 (+13) 👎
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/node_certificate_controller.go 67.47% (-8.21%) 83 (+9) 56 27 (+9) 👎
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/global/global.go 0.00% (-100.00%) 0 (-7) 0 (-7) 0 💀 💀 💀 💀 💀

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files:

  • github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/eviction/controller_test.go
  • github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/hypervisor_controller_test.go
  • github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/global/global_test.go

@fwiesel fwiesel added the enhancement New feature or request label Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant